# coding: utf-8
from PySide6.QtCore import Qt

from common import OthersIcon
from components import PodcastGalleryWidget, ScrollAreaWidget, CarouselMapWidget, CentreImageLabel


class DiscoverInterface(ScrollAreaWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.slidingWidget = CarouselMapWidget(self)
        self.__initWidgets()
        self.initDefaultData()

    def __initWidgets(self):
        self.slidingWidget.setFixedHeight(400)
        self.slidingWidget.start()
        self.verticalLayout.addWidget(self.slidingWidget, 0, Qt.AlignmentFlag.AlignTop)
        self.setObjectName('DiscoverInterface')

    def initDefaultData(self):
        def addImageLabel(pixmap: str):
            imageLabel = CentreImageLabel(pixmap, self)
            imageLabel.setBorderRadius(10, 10, 10, 10)
            return imageLabel

        self.slidingWidget.addWidgets([
            addImageLabel(OthersIcon.Default.path()), addImageLabel(OthersIcon.Default1.path()),
            addImageLabel(OthersIcon.Default4.path()), addImageLabel(OthersIcon.Default5.path())
        ])

        self.addGalleryWidget(
            title='本周排行',
            cards=[
                {
                    'pixmap': OthersIcon.Default.path(),
                    'title': 'Sunday Morning',
                    'body': '余杰'
                } for i in range(5)
            ]
        )

        self.addGalleryWidget(
            title='热门播客',
            cards=[
                {
                    'pixmap': OthersIcon.Default.path(),
                    'title': 'Sunday Morning',
                    'body': '余杰'
                } for i in range(5)
            ]
        )

        self.addGalleryWidget(
            title='热门歌手',
            cards=[
                {
                    'pixmap': OthersIcon.Default.path(),
                    'title': 'Sunday Morning',
                    'body': '余杰'
                } for i in range(5)
            ]
        )

        self.addGalleryWidget(
            title='认证歌手',
            singers=[
                {
                    'pixmap': OthersIcon.Default.path(),
                    'singer': '余杰'
                } for i in range(10)
            ]
        )

    def addGalleryWidget(self, title: str, cards: list = None, singers: list = None):
        galleryWidget = PodcastGalleryWidget(self)
        galleryWidget.setFixedHeight(350)
        self.verticalLayout.addWidget(galleryWidget, 0, Qt.AlignmentFlag.AlignTop)
        galleryWidget.setTitle(title)
        if cards:
            for card in cards:
                galleryWidget.addCard(**card)
        if singers:
            for singer in singers:
                galleryWidget.addSinger(**singer)
